package com.tuangou.tuangouheader.header.service.impl;

import com.tuangou.tuangouheader.header.dao.LevelDao;
import com.tuangou.tuangouheader.header.entity.LevelEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.tuangou.tuangouheader.header.dao.TuanzhangDao;
import com.tuangou.tuangouheader.header.entity.TuanzhangEntity;
import com.tuangou.tuangouheader.header.service.TuanzhangService;


@Service("tuanzhangService")
public class TuanzhangServiceImpl extends ServiceImpl<TuanzhangDao, TuanzhangEntity> implements TuanzhangService {

    @Autowired
    private TuanzhangDao tuanzhangDao;
    @Autowired
    private LevelDao levelDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TuanzhangEntity> page = this.page(
                new Query<TuanzhangEntity>().getPage(params),
                new QueryWrapper<TuanzhangEntity>()
        );

        return new PageUtils(page);
    }
    @Override
    public String shenhetg(Integer tzId) {

        tuanzhangDao.shenhetg(tzId);
        return "审核通过";


    }
    @Override
    public String shenhebtg(Integer tzId) {
        tuanzhangDao.bushenhetg(tzId);
        return "审核不通过";
    }

    @Override
    public List<TuanzhangEntity> findAll() {
        List<TuanzhangEntity> tuanzhangEntity = tuanzhangDao.selectList(null);
        for (TuanzhangEntity entity : tuanzhangEntity) {
            Integer lid = entity.getLid();
            LevelEntity levelEntity = levelDao.selectById(lid);
            if (2==entity.getStatus()){
                entity.setFee(levelEntity.getRate());
            }else {
                entity.setFee(BigDecimal.valueOf(0.00));
            }
            tuanzhangDao.updateById(entity);
        }
        return tuanzhangEntity;
    }

    @Override
    public TuanzhangEntity login(TuanzhangEntity tuanzhang) {

        return tuanzhangDao.login(tuanzhang);
    }


}